package com.yf.screenshot

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.graphics.PixelFormat
import android.os.Build
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.isy.gcdy.base.IConstants
import com.wink_172.library.callback.ICallback
import com.wink_172.library.model.Constants
import com.wink_172.library.utils.DisplayUtil
import com.wink_172.library.view.MySeekBar
import org.xutils.x


/**
 * DialogUtils
 * */
object DialogUtils {

    private const val TAG = "DialogUtils"


    /**
     * 下载进度框
     * */
    fun showProgressDialog(activity: Activity): Dialog {
        val dialog = Dialog(activity, com.wink_172.library.R.style.dialog)
        dialog.setContentView(com.wink_172.library.R.layout.progress_dialog)
        dialog.setCanceledOnTouchOutside(true)
        dialog.setCancelable(true)
        dialog.show()

        val title = dialog.findViewById<TextView>(com.wink_172.library.R.id.title)
        val hint = dialog.findViewById<TextView>(com.wink_172.library.R.id.hint)
        val progress = dialog.findViewById<MySeekBar>(com.wink_172.library.R.id.progress)
//        title.setText("正在下载...")


//        val all_size= args[0] as Int
//        val current_size= args[1] as Int
//        val processPP=(current_size.toFloat()/all_size.toFloat()*100).toInt()
//
//
//        hint.setText("下载进度（ "+processPP+"/100 )")
//        progress.currentProgress=processPP
//        progress.maxProgress=100
//        progress.invalidate()

        return dialog
    }

    /**title_str    content_str   btn_str
     * 单个确定按钮弹窗
     * cancel  true点即弹窗可消失
     */
    fun showSingleBtnDialog(
        activity: Activity,
        str1: String,
        str2: String,
        str3: String, cancel: Boolean,
        callback: com.wink_172.library.callback.ICallback?
    ): Dialog {
        val dialog = Dialog(activity, R.style.CustomProgressDialog)
        dialog!!.setContentView(R.layout.dialog_single_btn2)
        dialog!!.window!!.attributes.gravity = Gravity.CENTER
        dialog!!.setCancelable(cancel)
        dialog!!.setCanceledOnTouchOutside(false)
        dialog!!.show()

        val title_view = dialog!!.findViewById<TextView>(R.id.title_view)
        val content_view = dialog!!.findViewById<TextView>(R.id.content_view)
        val btn_confirm = dialog!!.findViewById<TextView>(R.id.btn_confirm)

        title_view.text = str1
        content_view.text = str2

        btn_confirm.text = str3
        btn_confirm.setOnClickListener(View.OnClickListener {

            dialog.dismiss()
            if (callback != null) {
                callback.onSendEvent(IConstants.EventEnum.单个确定按钮点击回调.ordinal)
            }

        })


        return dialog
    }

    /**
     * 只展示标题不展示content
     * 展示普通通用弹窗  左右双按钮
     * str1标题
     * str2左按钮
     * str3右按钮
     */
    fun showCommonDialog(
        activity: Activity,
        str1: String,
        str2: String,
        str3: String,
        callback: ICallback
    ): Dialog {
        val dialog = Dialog(activity, R.style.CustomProgressDialog)
        dialog!!.setContentView(R.layout.dialog_common)
        dialog!!.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        dialog!!.window!!.attributes.gravity = Gravity.CENTER
        dialog!!.show()
        val title_view = dialog!!.findViewById<TextView>(R.id.title_view)
        val content_view = dialog!!.findViewById<TextView>(R.id.content_view)
        val btn_cancel = dialog!!.findViewById<TextView>(R.id.btn_cancel)
        val btn_confirm = dialog!!.findViewById<TextView>(R.id.btn_confirm)

        content_view.visibility = View.GONE
        title_view.text = str1
        btn_cancel.text = str2
        btn_confirm.text = str3
        btn_cancel.setOnClickListener {
            dialog.dismiss()
            callback.onSendEvent(IConstants.EventEnum.拒绝.ordinal)
        }

        btn_confirm.setOnClickListener {
            dialog.dismiss()
            callback.onSendEvent(IConstants.EventEnum.同意.ordinal)
        }


        return dialog
    }





}